<?php
/***
 * nft
 */
namespace app\api\controller;

use app\api\controller\BaseController;

class FileController extends BaseController{
	
    public function upload(){
		//二维码图片
		$file = request()->file('file');

		//上传路径
		$uploadPath = './upload/file/app';
		if(!is_dir($uploadPath)) mkdir($uploadPath, 0777, true);

		$info = $file->validate(['size'=>1000*1024*5,'ext'=>'jpg,png,gif,jpeg'])->rule('date')->move($uploadPath);
		if($info){
			// 成功上传后 获取上传信息
			return json(['code'=>1,'data'=>$_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].ltrim($uploadPath, '.').'/'.$info->getSaveName()]);
		}else{
			// 上传失败获取错误信息
			return json(['code'=>0,'code_dec'=>$file->getError()]);
		}
    }

}
